package org.baseflexcharts.charts
{
	import mx.collections.ArrayCollection;
	
	import org.baseflexcharts.backgrounds.GridBackground;
	import org.baseflexcharts.databoard.YOnlyBarDataBoard;
	import org.baseflexcharts.rules.HorizontalRule;
	import org.baseflexcharts.rules.VerticalRule;
	import org.baseflexcharts.shapes.Legend;
	
	public class YOnlyBarChart extends YOnlyCoordinateChart
	{				
		public function YOnlyBarChart()
		{
			super();
		}
				
		protected override function drawMaterials():void
		{
			var legendData:ArrayCollection = new ArrayCollection();
			
			for (var i:uint; i < dataColors.length && i < dataNames.length; i++)
			{
			    legendData.addItem({name: dataNames[i], color: dataColors[i]});	
			}
			
			var legend:Legend = new Legend();
			legend.dataProvider = legendData;
			legend.direction = Legend.HORIZONTAL;
			legend.type = Legend.TYPE_RECT;
			legend.xOffset = 90;
			legend.x = this.verticalRuleWidth;
			legend.y = 0;
			legend.draw();
			
			this.addChild(legend);
		}					
		
		protected override function drawDataBoard():void
		{
			var length:uint = dataBoardDataProvider.length;
			
			for (var i:uint = 0; i < length; i++)
			{
				var board:YOnlyBarDataBoard = new YOnlyBarDataBoard();
				
				board.x = this.verticalRuleWidth;
				board.y = legendHeight;
				board.width = this.width - this.verticalRuleWidth;
				board.height = this.height - this.horizontalRuleHeight - legendHeight;
				board.xAmount = this.xDataProvider.length;
				board.yAmount = this.yDataProvider.length;
				board.yUnitValue = this.yUnitValue;
				board.leftMargin = this.xOffset;
				board.rightMargin = this.rightMargin;
				board.topMargin = this.topMargin;
				board.bottomMargin = this.yOffset;
				board.lineWeight = this.lineWeight;
				board.lineColor = this.dataColors[i];
				board.lineAlpha = this.lineAlpha;
				
				var unitWidth:uint = (board.width - board.leftMargin - board.rightMargin) / (board.xAmount - 1);
			    
			    if (board.barWidth == 0) 
			    {
			    	board.barWidth = unitWidth / 4;
			    }
			    
			    var totalWidth:Number = board.barWidth * length;
			    			    
				board.xOffset = -(totalWidth / 2) + board.barWidth * i;
				
				board.dataProvider = dataBoardDataProvider[i];
				
				board.draw();
				
				this.addChild(board);
			}
		}				
	}
}